package com.student.model;

import java.sql.Timestamp;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * Company entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.student.model.Company
 * @author MyEclipse Persistence Tools
 */

public class CompanyDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(CompanyDAO.class);
	// property constants
	public static final String LOGINID = "loginid";
	public static final String PASSWORD = "password";
	public static final String COMPANYNAME = "companyname";
	public static final String DETAILS = "details";
	public static final String COMPANYADDRESS = "companyaddress";
	public static final String POST = "post";
	public static final String TELEPHONE = "telephone";
	public static final String WORKADDRESS = "workaddress";
	public static final String LINKMAN = "linkman";
	public static final String WANTCOUNT = "wantcount";
	public static final String UNITKIND = "unitkind";
	public static final String FINANCING = "financing";
	public static final String EMPLOYEECOUNT = "employeecount";
	public static final String WEBSITE = "website";
	public static final String FAX = "fax";
	public static final String TRADE = "trade";
	public static final String EMAIL = "email";
	public static final String LICENCE = "licence";
	public static final String AUDITING = "auditing";
	public static final String REMARK = "remark";

	public void save(Company transientInstance) {
		log.debug("saving Company instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Company persistentInstance) {
		log.debug("deleting Company instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Company findById(java.lang.Long id) {
		log.debug("getting Company instance with id: " + id);
		try {
			Company instance = (Company) getSession().get(
					"com.student.model.Company", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Company instance) {
		log.debug("finding Company instance by example");
		try {
			List results = getSession().createCriteria(
					"com.student.model.Company").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Company instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Company as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByLoginid(Object loginid) {
		return findByProperty(LOGINID, loginid);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByCompanyname(Object companyname) {
		return findByProperty(COMPANYNAME, companyname);
	}

	public List findByDetails(Object details) {
		return findByProperty(DETAILS, details);
	}

	public List findByCompanyaddress(Object companyaddress) {
		return findByProperty(COMPANYADDRESS, companyaddress);
	}

	public List findByPost(Object post) {
		return findByProperty(POST, post);
	}

	public List findByTelephone(Object telephone) {
		return findByProperty(TELEPHONE, telephone);
	}

	public List findByWorkaddress(Object workaddress) {
		return findByProperty(WORKADDRESS, workaddress);
	}

	public List findByLinkman(Object linkman) {
		return findByProperty(LINKMAN, linkman);
	}

	public List findByWantcount(Object wantcount) {
		return findByProperty(WANTCOUNT, wantcount);
	}

	public List findByUnitkind(Object unitkind) {
		return findByProperty(UNITKIND, unitkind);
	}

	public List findByFinancing(Object financing) {
		return findByProperty(FINANCING, financing);
	}

	public List findByEmployeecount(Object employeecount) {
		return findByProperty(EMPLOYEECOUNT, employeecount);
	}

	public List findByWebsite(Object website) {
		return findByProperty(WEBSITE, website);
	}

	public List findByFax(Object fax) {
		return findByProperty(FAX, fax);
	}

	public List findByTrade(Object trade) {
		return findByProperty(TRADE, trade);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByLicence(Object licence) {
		return findByProperty(LICENCE, licence);
	}

	public List findByAuditing(Object auditing) {
		return findByProperty(AUDITING, auditing);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findAll() {
		log.debug("finding all Company instances");
		try {
			String queryString = "from Company";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Company merge(Company detachedInstance) {
		log.debug("merging Company instance");
		try {
			Company result = (Company) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Company instance) {
		log.debug("attaching dirty Company instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Company instance) {
		log.debug("attaching clean Company instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}